import mysql from 'mysql2/promise'

export async function query({ query, values = [] }) {
  const connection = await mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'your_password',
    database: 'your_database'
  })

  try {
    const [results] = await connection.execute(query, values)
    return results
  } finally {
    connection.end()
  }
}

export async function getAppVersion() {
  const result = await query({
    query: 'SELECT version FROM app_version ORDER BY id DESC LIMIT 1',
    values: [],
  })
  return result[0]?.version || '1.0.0'
}

export async function updateAppVersion() {
  await query({
    query: 'INSERT INTO app_version (version, update_time) VALUES (?, NOW())',
    values: [Date.now().toString()],
  })
}